package com.xinsteel.cyjk.contract.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.xinsteel.cyjk.contract.service.CyjkService;
import com.xinsteel.cyjk.contract.utils.AES;
import org.springframework.stereotype.Service;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Map;

@Service
public class CyjkServiceImpl implements CyjkService {

    @Override
    public String encryptionUrl(String queryJson) {
        Map<String,String> map = JSONObject.parseObject(queryJson, Map.class);
        String phone = map.get("phone");
        String staffno = map.get("staffno");
        String fromFlag = "xingang";
        String  url = "weixin://dl/business/?appid=wx017137fe2603b550&path=pages/login/middlePage/middlePage";
//        String key = "LCaCuNoodCDziUMkxJaRjrjyvoENgrXX";
        String key = "ISqYLrMmC7dz4WsSBMNI072J4A4vXX5d";
        String sign = staffno+ "," + phone + "," + "wx017137fe2603b550";
        String encrypt = AES.encrypt(sign, key);
        String query = "mobile=" + phone + "&staffno=" + staffno + "&fromFlag=" + fromFlag + "&sign=" +encrypt;
        try {
            String encode = URLEncoder.encode(query,"GBK");
            url = url + "&query=" +encode;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return url;
    }

    @Override
    public String encryptionMarketUrl(String queryJson) {
        Map<String,String> map = JSONObject.parseObject(queryJson, Map.class);
        String phone = map.get("phone");
        String staffNo = map.get("staffNo");
        String  url = "weixin://dl/business/?appid=wxc3606e314d2c232e&path=pages/index/index";
//        String key = "LCaCuNoodCDziUMkxJaRjrjyvoENgrXX"; 
        String key = "ISqYLrMmC7dz4WsSBMNI072J4A4vXX5d";
        String sign = staffNo+ "," + phone + "," + "wxc3606e314d2c232e";
        String encrypt = AES.encrypt(sign, key);
        String query = "mobile=" + phone + "&staffNo=" + staffNo  + "&sign=" +encrypt;
        try {
            String encode = URLEncoder.encode(query,"GBK");
            url = url + "&query=" +encode;
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return url;
    }

}
